From 23bc606c793a967e5c0efa5337474c6f36b7f3fc Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 22 Jun 2011 17:39:38 -0400 Subject: [PATCH] a11y: add a treeview performance test This test creates a treeview with a few columns and a liststore, and then populates it with a 1000 rows. --- tests/a11y/Makefile.am | 37 ++++-- tests/a11y/tree-performance.c | 220 ++++++++++++++++++++++++++++++++++ 2 files changed, 248 insertions(+), 9 deletions(-) create mode 100644 tests/a11y/tree-performance.c diff --git a/tests/a11y/Makefile.am b/tests/a11y/Makefile.am index 827f35f4d1..483e0fcda1 100644 --- a/tests/a11y/Makefile.am +++ b/tests/a11y/Makefile.am @@ -5,22 +5,41 @@ TEST_PROGS += accessibility-dump check_PROGRAMS = $(TEST_PROGS) accessibility_dump_CFLAGS = \ - -I$(top_srcdir) \ - -I$(top_builddir)/gdk \ - -I$(top_srcdir)/gdk \ - -DGDK_DISABLE_DEPRECATED \ - -DGTK_DISABLE_DEPRECATED \ - $(GTK_DEBUG_FLAGS) \ - $(GTK_DEP_CFLAGS) + -I$(top_srcdir) \ + -I$(top_builddir)/gdk \ + -I$(top_srcdir)/gdk \ + -DGDK_DISABLE_DEPRECATED \ + -DGTK_DISABLE_DEPRECATED \ + $(GTK_DEBUG_FLAGS) \ + $(GTK_DEP_CFLAGS) accessibility_dump_LDADD = \ - $(top_builddir)/gdk/libgdk-3.la \ - $(top_builddir)/gtk/libgtk-3.la \ + $(top_builddir)/gdk/libgdk-3.la \ + $(top_builddir)/gtk/libgtk-3.la \ $(GTK_DEP_LIBS) accessibility_dump_SOURCES = \ accessibility-dump.c +TEST_PROGS += tree-performance + +tree_performance_CFLAGS = \ + -I$(top_srcdir) \ + -I$(top_builddir)/gdk \ + -I$(top_srcdir)/gdk \ + -DGDK_DISABLE_DEPRECATED \ + -DGTK_DISABLE_DEPRECATED \ + $(GTK_DEBUG_FLAGS) \ + $(GTK_DEP_CFLAGS) + +tree_performance_LDADD = \ + $(top_builddir)/gdk/libgdk-3.la \ + $(top_builddir)/gtk/libgtk-3.la \ + $(GTK_DEP_LIBS) + +tree_performance_SOURCES = \ + tree-performance.c + EXTRA_DIST += \ hello-world.ui hello-world.txt \ mnemonic.ui mnemonic.txt \ diff --git a/tests/a11y/tree-performance.c b/tests/a11y/tree-performance.c new file mode 100644 index 0000000000..76865a6e2b --- /dev/null +++ b/tests/a11y/tree-performance.c @@ -0,0 +1,220 @@ +/* + * Copyright (C) 2011 Red Hat Inc. + * + * Author: + * Matthias Clasen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +const gchar treeui[] = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " OneTwoThreeTrue5050" + " " + " " + " " + " " + " " + " True" + " liststore1" + " " + " " + " First column" + " " + " " + " " + " " + " 0" + " " + " " + " " + " " + " " + " " + " 3" + " " + " " + " " + " " + " " + " " + " Second column" + " " + " " + " " + " " + " 1" + " " + " " + " " + " " + " " + " " + " 4" + " " + " " + " " + " " + " " + " " + " " + ""; + +static void +walk_accessible_tree (AtkObject *accessible, + gpointer data) +{ + gint *count = data; + gint i; + + (*count)++; + + for (i = 0; i < atk_object_get_n_accessible_children (accessible); i++) + { + AtkObject *child = atk_object_ref_accessible_child (accessible, i); + walk_accessible_tree (child, data); + g_object_unref (child); + } +} + +static GtkWidget * +builder_get_toplevel (GtkBuilder *builder) +{ + GSList *list, *walk; + GtkWidget *window = NULL; + + list = gtk_builder_get_objects (builder); + for (walk = list; walk; walk = walk->next) + { + if (GTK_IS_WINDOW (walk->data) && + gtk_widget_get_parent (walk->data) == NULL) + { + window = walk->data; + break; + } + } + + g_slist_free (list); + + return window; +} + +static void +populate_tree (GtkBuilder *builder) +{ + GtkTreeView *tv; + GtkListStore *store; + GtkTreeIter iter; + gint i; + + tv = (GtkTreeView *)gtk_builder_get_object (builder, "treeview1"); + store = (GtkListStore *)gtk_tree_view_get_model (tv); + + /* append a thousand rows */ + for (i = 0; i < 1000; i++) + { + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, "Bla", 1, "Bla bla", 2, "Bla bla bla", 3, i % 2 == 0 ? TRUE : FALSE, 4, i % 100, 5, i, -1); + } +} + +static void +test_performance_tree (void) +{ + GtkBuilder *builder; + gdouble elapsed; + GtkWidget *window; + GError *error = NULL; + + builder = gtk_builder_new (); + gtk_builder_add_from_string (builder, treeui, -1, &error); + g_assert_no_error (error); + window = builder_get_toplevel (builder); + g_assert (window); + + gtk_widget_show (window); + + g_test_timer_start (); + + populate_tree (builder); + + elapsed = g_test_timer_elapsed (); + g_test_minimized_result (elapsed, "large tree test: %gsec", elapsed); + g_object_unref (builder); +} + +static void +test_a11y_performance_tree (void) +{ + GtkBuilder *builder; + gdouble elapsed; + GtkWidget *window; + GError *error = NULL; + gint count_before; + gint count_after; + + builder = gtk_builder_new (); + gtk_builder_add_from_string (builder, treeui, -1, &error); + g_assert_no_error (error); + window = builder_get_toplevel (builder); + g_assert (window); + + gtk_widget_show (window); + + g_test_timer_start (); + + /* make sure all accessibles exist */ + count_before = 0; + walk_accessible_tree (gtk_widget_get_accessible (window), &count_before); + + populate_tree (builder); + + /* for good measure, do this again */ + count_after = 0; + walk_accessible_tree (gtk_widget_get_accessible (window), &count_after); + + elapsed = g_test_timer_elapsed (); + g_test_minimized_result (elapsed, "large tree test with a11y: %gsec", elapsed); + g_object_unref (builder); + + g_test_message ("%d accessibles before, %d after\n", count_before, count_after); +} + +int +main (int argc, char *argv[]) +{ + gtk_test_init (&argc, &argv, NULL); + + if (!g_test_perf ()) + return 0; + + g_test_add_func ("/performance/tree", test_performance_tree); + g_test_add_func ("/a11y/performance/tree", test_a11y_performance_tree); + + return g_test_run (); +} -- 2.30.2